﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Linq.Dynamic;
using System.Text;
using System.Linq.Expressions;
using System.Reflection;
using System.Reflection.Emit;
using System.Threading;

namespace SWGeneracionE.Libraries
{
    public static class ExtraFunctions
    {
        public static IQueryable<T> OrderAndPaging<T>(this IQueryable<T> source, int jtStartIndex, int jtPageSize, string jtSorting)
        {
            return (IQueryable<T>)OrderAndPaging((IQueryable)source, jtStartIndex, jtPageSize, jtSorting);
        }

        public static IQueryable OrderAndPaging(this IQueryable source, int jtStartIndex, int jtPageSize, string jtSorting)
        {
            source = source.OrderBy(jtSorting);
            return jtPageSize > 0
                   ? source.Skip(jtStartIndex).Take(jtPageSize) //Paging
                   : source; //No paging
        }
    }
}